当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Mysqli prepared statement issue with get_result

问题描述:

I have been using the traditional method of query db with out prepared statement. So decided to move to prepared statement now as below are my codes.

$link = new mysqli(dbHost, dbUser, dbPassword, dbDatabase);

if($link->connect_error) {

die('bind_param() failed: ' . htmlspecialchars($link->connect_error));

}

$stmt = $link->stmt_init();

$selectQuery1 ="Select * From tblUser Where tblUser.userName=? ";

$stmt1 = mysqli_prepare($link, $selectQuery1);

if ( false===$stmt1 ) {

die('stmt1 prepare() failed: ' . htmlspecialchars($mysqli->error));

}

$rc1 = $stmt1->bind_param('s', $userName);

if ( false===$rc ) {

die('rc1 bind_param() failed: ' . htmlspecialchars($stmt1->error));

}

$execute1 = $stmt1->execute();

if ( false===$execute1 ) {

die('execute1 execute() failed: ' . htmlspecialchars($stmt1->error));

}

$store1=$stmt1->store_result();

if ( false===$store1 ) {

die('store1() failed: ' . htmlspecialchars($stmt1->error));

}

$count1=$stmt1->num_rows;

$result1 = $stmt1->get_result();

if ( false===$result1 ) {

die('result1 () failed: ' . htmlspecialchars($stmt1->error));

}

The query worked well till this line $count1=$stmt1->num_rows; and the moment I put this codes $result1 = $stmt1->get_result(); my page failed and I found out that I must now change to mysql native driver etc. My biggest worry is by changing the driver it might effect all my other existing application. So what is the best mechanism to mitigate is there any other method to retrieve the result or move to PDO ? I want to be able to use this mechanism mysql_fetch_array($result, MYSQL_ASSOC) to get my select results ?

分享给朋友:
您可能感兴趣的文章:
随机阅读: