php - mysqli version of mysql pattern -
here's mysql pattern in php:
$username="username"; $password="password"; $database="username-databasename"; // opens connection mysql server $connection=mysql_connect (localhost, $username, $password); if (!$connection) { die("not connected : " . mysql_error()); } // set active mysql database $db_selected = mysql_select_db($database, $connection); if (!$db_selected) { die ("can\'t utilize db : " . mysql_error()); } // search rows in markers table $query = query $result = mysql_query($query);
i tried replace of mysqli pattern , stick query part @ bottom so:
//database info $db_host = "localhost"; //host address (most localhost) $db_name = "username-databasename"; //name of database $db_user = "username"; //name of database user $db_pass = "password"; //password database user /* create new mysqli object database connection parameters */ $mysqli = new mysqli($db_host, $db_user, $db_pass, $db_name); global $mysqli; if ($mysqli->connect_errno) { echo "<p>mysql error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>"; exit(); } // search rows in markers table $query = query $result = mysql_query($query);
however, error message:
invalid query: no database selected
what doing wrong?
first of all, you're calling mysql_query
, not mysqli_query
, intended to.
second, since you're using object oriented form, need phone call mysqli_query
method:
$result = $mysqli->query($query);
php mysql mysqli
No comments:
Post a Comment