php - Mysql query to mysqli query UPDATE statement -
im trying convert mysql query mysqli doesnt work...why? from:
mysql_query("update views set views=views+1 viewid='1'"); to:
$q1 = $mysqli->query("update views set views=views+1 viewid='1'"); notice: undefined variable: mysqli in
fatal error: phone call fellow member function query() on non-object
when do
mysqli_query("update views set views=views+1 viewid='1'"); mysqli_query expects 2 parameters
because have not initialized mysqli object named $mysqli. there 2 ways of doing that
procedural
if want procedural way this
$q1 = mysqli_query($connection,"update views set views=views+1 viewid=1"); where $connection result of mysqli_connect, this
$connection = mysqli_connect("localhost", "my_user", "my_password", "my_database"); oop
if want oop way, need initialize $mysqli this
$mysqli = new mysqli("localhost", "my_user", "my_password", "my_database"); and can query like
$q1=$mysqli->query("update views set views=views+1 viewid=1"); manual
php
No comments:
Post a Comment