【问题标题】:Can't connect MySQLfrom a PHP script无法从 PHP 脚本连接 MySQL
【发布时间】:2017-02-12 08:08:28
【问题描述】:

我需要学习一个事务型数据库,但我无法连接到 MySQL:

#!/usr/bin/php

<?php
$link = new mysql_connect('localhost', 'root', '123456789');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>

我得到了输出:

PHP 致命错误:在第 4 行的 /root/test01.php 中找不到类 'mysql_connect'

问题是什么,我该如何解决?

【问题讨论】:

  • 好消息,现在你将无法使用过时的 mysql_* 函数

标签: php mysql shell centos


【解决方案1】:

如下删除“新”;因为 mysql_connect 是一个函数。

<?php
$link = mysql_connect('localhost', 'root', '123456789');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>

【讨论】:

  • 你能帮我吗 Python Code sql = "SELECT (case when user1 = '1' THEN 'true' ELSE 'false' END) AS IsEmtpy from dt" sql1= "DELETE FROM dt WHERE user1 = '%i' " %(1) try: cursor.execute(sql) if sql == true: cursor.execute(sql1) print "Sucuess" else: print "error" print "Error"
  • 我是新手,只接受了由 Mit CPC 撰写的所有答案,反之亦然..chk 他们的帐户..
猜你喜欢
  • 2019-07-20
  • 2019-03-25
  • 1970-01-01
  • 2014-05-22
  • 1970-01-01
  • 2018-09-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多