Saturday, 15 January 2011

php - MySQL to MySQLi (get num_rows) -



php - MySQL to MySQLi (get num_rows) -

i have problem switching mysql mysqli. tried next code using mysql , works fine. when switch mysqli returns null value.

mysql (works fine)

public function login_user($username, $password) { $md5_password = md5($password); $query = mysql_query("select uid users username='$username' , password='$md5_password'"); if(mysql_num_rows($query) == 1) { $row=mysql_fetch_array($query); homecoming $row['uid']; } }

mysqli (the $numrows null)

public function login_user($username, $password) { $md5_password = md5($password); $query = mysqli_query($connection, "select uid users username='$username' , password='$md5_password'"); $numrows = mysqli_num_rows($query); echo "username: " . $username . ", password: " . $password . "<br/>"; echo "rows: " . $numrows; if($numrows == 1) { $row = mysqli_fetch_array($query, mysqli_assoc); homecoming $row['uid']; } }

database connection (mysql)

$dbc = @mysql_connect ('localhost','root','') or die ('could not connect mysql: ' . mysql_error() ); mysql_select_db ('socialhouse') or die ('problems selecting database: ' . mysql_error() );

database connection (mysqli)

$connection = mysqli_connect('localhost', 'root', '', 'socialhouse'); if (mysqli_connect_errno()) { echo "failed connect mysql: " . mysqli_connect_error(); exit();}

does know wrong mysqli code? in advance

because have pass $connection variable script mysqli extension, you're attempting access variable outside scope of function. pass argument function , should go.

php mysql mysqli mysql-num-rows

No comments:

Post a Comment