dongxieyou3314 2019-05-15 01:01
浏览 44

MySQL i Prepared Statement不会产生错误或结果[重复]

This seems to be a simple insert of information into the database using prepared statements & MYSQLi, yet I only get results if the data is inserted in the old manor (not secure):

$write = mysql_query("INSERT INTO stats VALUES('','$pagename','$network','$duration','$statvote','',INET_ATON('$ip'),NOW())");

I am using:

Server version: 5.6.43 - MySQL Community Server (GPL) PHP Version 5.6.40 API Extensions Enabled mysql,mysqli,pdo_mysql

I have made sure MYSQLi is present:

if (!function_exists('mysqli_init') && !extension_loaded('mysqli')) {
    echo 'We don\'t have mysqli!!!';
} else {
    echo 'Yes we have it!';
} 

....and checked on the command line with:

php -m | grep -i mysql

and received:

mysql
mysqli
mysqlnd
pod_mysql

I conneect sucessfully..

// Create connection
//                  servername   username          PW          dbname
$conn = new mysqli(localhost, ***************, ***********, ************);

// Check connection
//if (mysqli_connect_error()) { echo mysqli_connect_error(); exit;}

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
echo "Connected successfully";

The main code to insert a record is:

// Test variables
$pagename= 'Test';
$network = 'MMM';
$duration = 60;
$statvote = 1;
$username = 'star';
$ip = $_SERVER['REMOTE_ADDR']; ///gets visitor IP address


// the ??????? below are parameter markers used for variable binding..this is a Template
$write = "INSERT INTO stats (showname,network,duration,vote,username,ip,timevoted) VALUES(?,?,?,?,?,INET_ATON(?),NOW())";

//prepare 
$stmt = $conn->prepare($write);

//  Bind                  
$stmt-> bind_param("ssiisss",$pagename,$network,$duration,$statvote,$username,INET_ATON($ip),NOW());


$stmt->execute();

$stmt->close();

$conn->close();

I expected a record to be placed onto the end of the database, but I receive no error messages($stmt->error and mysqli_error($stmt),.. almost as if the code is not there. I have checked the site, and have seen discussions that I thought were solutions, like not including the "Id" in the prepared statement ,using INET_ATON(?) in the prepared statement, and making sure the variable types were correct(s,i,d,b). But my results were the same.

Is there anything else wrong with my specific code?

Thanks

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
    • ¥15 Python报错怎么解决
    • ¥15 simulink如何调用DLL文件
    • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
    • ¥30 线性代数的问题,我真的忘了线代的知识了
    • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
    • ¥188 需要修改一个工具,懂得汇编的人来。
    • ¥15 livecharts wpf piechart 属性
    • ¥20 数学建模,尽量用matlab回答,论文格式
    • ¥15 昨天挂载了一下u盘,然后拔了