[英]Php command line script can't connect to server using MYSQLI
I have this command line script I am trying to use. 我有要使用的命令行脚本。 It adds image to an already present database and table.
它将图像添加到已经存在的数据库和表中。 The server has Wamp server installed on it and I can access it from a different computer.
该服务器上安装了Wamp服务器,我可以从其他计算机上访问它。 But everytime I run the script the script just hangs when connecting.
但是每次我运行脚本时,脚本都会在连接时挂起。
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$filename = $argv[1];
//$filename="images/image10.jpg";
$imgData = file_get_contents($filename);
$size = getimagesize($filename);
$servername="192.168.0.34";
$username="root";
$password="password";
$dbname = "test";
$conn = new mysqli($servername, $username, $password, $dbname);
// check connection
if($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connection successful";
// insert into table
$sql = sprintf("insert into images(image_type, image, image_size, image_name) values('%s', '%s', '%d', '%s')",
mysql_real_escape_string($size['mime']),
mysql_real_escape_string($imgData),
$size[3],
mysql_real_escape_string($_FILES['userfile']['name']));
if($conn->query($sql) === TRUE) {
echo "Inserted new image successfully";
} else {
echo "Error inserting image: " . $conn->error;
}
echo "Closing the connection";
$conn = null;
?>
I have only installed php and php-mysql on the client. 我只在客户端上安装了php和php-mysql。 The client is running debian and the sever is running windows 7. Am I missing something else I need to install?
客户端正在运行debian,服务器正在运行Windows7。我是否还需要安装其他东西?
Thank you 谢谢
You need to install mysqli
on your system. 您需要在系统上安装
mysqli
。 See: http://php.net/manual/en/mysqli.installation.php 参见: http : //php.net/manual/en/mysqli.installation.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.