简体   繁体   English

PHP命令行脚本无法使用MYSQLI连接到服务器

[英]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.

相关问题 无法通过 PHP 脚本连接到 GoDaddy mysqli 数据库 - Can't connect to GoDaddy mysqli database via PHP script 为什么我无法使用 mysqli_connect 和 PHP 7.4 连接到 MySQL 5.3.36 共享服务器,但使用 php 7 可以工作? - Why I can't connect to a MySQL 5.3.36 shared server using mysqli_connect and PHP 7.4, but it will work using php 7.1? Apache PHP脚本无法连接到远程数据库/ ODBC / MySQL,但可以从命令行运行 - Apache PHP script can't connect to remote database/ODBC/MySQL but works from command line 无法在php脚本中使用mysqli连接到mysql - cannot connect to mysql using mysqli in php script 可以通过命令行连接,但不能通过PHP脚本连接 - Can connect via command line but not via a PHP script 我可以在命令行中远程连接到 mySQL 数据库,但不能使用 php 脚本 - I can remotely connect to mySQL database in command line, but not with php script php无法连接到错误13的mysql(但命令行可以) - php can't connect to mysql with error 13 (but command line can) 为什么PHP脚本无法通过命令行或任务计划程序在Server 2008上写入文件? - Why can’t PHP script write a file on server 2008 via command line or task scheduler? 无法使用PHP连接到我的MySQL数据库mysqli_connect() - Can't connect to my MySQL database using PHP mysqli_connect() 不能通过Web浏览器在Windows上的PHP上使用mysqli,但可以从命令行使用 - Can't use mysqli with PHP on Windows from web-browser, but it works from command line
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM