1
我用插入在PHP中值是这样的:PHP INSERT的MySQL 5.7
$sql = " INSERT INTO `table` (name, email) VALUES ('$name','$email') ";
考虑到我的表有以下几列:ID,姓名,电子邮件地址,电话
在MySQL 5.7它不会让我再做这个查询,因为它说地址没有默认值。
我为它添加一个默认值在MySQL,但有些领域不容许默认值,像一滴,文字...
我的问题是:我总是有来形容我的表中的每一列我查询,所以它可以工作?像:
$sql = " INSERT INTO `table` (id,name, email, address, phone)
VALUES ('', '$name','$email', '', '') ";
***你的脚本是在对SQL注入攻击的风险。(http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) ***。 [Escaping the string](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string)并不安全!了解[PDO](http://php.net/manual/en/pdo.prepared-statements.php)和[MySQLi]([准备](http://en.wikipedia.org/wiki/Prepared_statement) http://php.net/manual/en/mysqli.quickstart.prepared-statements.php)并考虑使用PDO,[这真的很简单](http://jayblanchard.net/demystifying_php_pdo.html)。 –
为什么连接字符串而不是使用[prepared statements](https://secure.php.net/manual/en/pdo.prepare.php)? – Artemis
如果你可以有一个BLOB列的默认值,它会是什么? –