我对MySQL几乎一无所知,我在这里遇到了问题:
let queue = NSOperationQueue()
queue.qualityOfService = .UserInitiated
let primaryKey = downloadable.primaryKey
// this code is executed on imageDidLoad()
queue.addOperationWithBlock {
let realm = Realm()
realm.refresh()
realm.write {
realm.create(DownloadableClass.Self, value: ["primaryKey" : primaryKey, "imageData" : imageData], update: true)
}
}
它说问题在文件的第19行,而那是我在那里发现的:
mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead
我的问题是如何修复代码?我需要改变吗?
感谢您阅读本文,欣赏它。
答案 0 :(得分:1)
要删除弃用警告并安全地升级到将来的PHP版本,您可以使用此处记录的PDO抽象层:http://php.net/manual/en/book.pdo.php
要使用PDO,我们需要安装PHP-MySQL-PDO驱动程序,例如在Ubuntu:
apt-get install php5-mysql (provide PHP-Mysql-PDO
您必须首先创建PDO对象的新实例:
$dsn = 'mysql:dbname=testdb;host=127.0.0.1';
$user = 'dbuser';
$password = 'dbpass';
try {
$dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
然后准备一份要执行的陈述:
$stmt = $dbh->prepare("INSERT INTO REGISTRY (name, value) VALUES (:name, :value)");
$stmt->bindParam(':name', $name);
$stmt->bindParam(':value', $value);
// insert one row
$name = 'one';
$value = 1;
$stmt->execute();