主要问题是,过去一周我无法让我的脚本运行查询。
我正在运行wamp apache 2.4,php 5.5和mysql 5.6
if ($flag == true) {
//try to connect to db with given parameters
// minimal validation to make sure no input was sent in error so now i can begin code to connect to database
// using the pdo php data object extension
print 'all input validated';
$host= "127.0.0.1";
$db_name ="theturnbuckle";
$port= "3306";
$dbusername= 'root';
$dbpassword= '';
//registration details including host, port and database name
$dsn = "mysql:host=$host;port=$port;dbname=$db_name;";
//error handling for connection
try {
$db = new PDO($dsn, $dbusername, $dbpassword);
//if no proplems flag a variable for connection status which is to be used later.
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setFetchMode(PDO::FETCH_ASSOC);
//first query to test that the username is not in the database.
$username = $_POST['username'];
$userquery = "SELECT username FROM registation_view WHERE username = :username" ;
//second query to test for existing email
$email = $_POST['email'];
$emailquery = "SELECT email FROM registation_view WHERE email = :email";
//preparing statement, binding html input to variables to be used in the prepared statement.
$db = new PDO($dsn, $dbusername, $dbpassword);
$stmt = $db->prepare($userquery);
$stmt->bindParam(':username', $username, PDO::PARAM_STR, 15);
//execute the query in variable
$stmt->execute($userquery);
if ($stmt->fetchColumn() > 0){
print 'Sorry ' .$username . 'is already in use please try another';
}//else the username is not is use as fetchColumn is null or the if is false
else {$registerprocess === true;}
$db = new PDO($dsn, $dbusername, $dbpassword);
$stmt = $db->prepare($emailquery);
$stmt->bindParam(':email', $email, PDO::PARAM_STR, 15);
$stmt->execute($emailquery);
if ($stmt->fetchColumn() > 0){
print 'Sorry ' .$_POST['email'] . 'is already in use please try another';
$registerprocess === false;
}//else the email is not is use as fetchColumn is not > 0 so the registration proceeds.
else {$registerprocess === true;}
// catch (PDOException $e){
//die("Unable to run query: " . $e->getMessage());}
if ($registerprocess === true) {
//username and email are not on record so i am free to INSERT data into database
$query = "INSERT INTO registration_view (username, password, email, gender, date_of_birth, joindate)
VALUES (?, ?, ?, ?, ?, ?)";
$joindate = now();
$date_of_birth = $_POST['day'] . $_POST['month'] . $_POST['year'];
$stmt->prepare($query);
$stmt->bindParam(1, $_POST['username'], PDO::PARAM_STR, 20) ;
$stmt->bindParam(2, $_POST['password'], PDO::PARAM_STR, 20) ;
$stmt->bindParam(3, $_POST['email'], PDO::PARAM_STR, 20) ;
$stmt->bindParam(4, $_POST['gender']) ;
$stmt->bindParam(5, $date_of_birth) ;
$stmt->bindParam(6, $joindate) ;
$stmt->execute();
print ' Welcome ' .$username . 'you are now registered';
}
} catch (PDOException $e) {
die("Unable to connect: " . $e->getMessage());
}
}//INPUT VALIDATION IF
这是我的代码,第一个标志是一旦数据验证成功完成那么多工作和打印'验证'就继续;证实了这一点。
我确定$ dsn没有出错,因为之前显示的错误是用单引号括起来的,现在没有显示这样的错误。
虽然我对代码是一团糟,但我也经历了php.ini my.ini和apache.config,但是一周说没有运气。
我可以添加任何帮助(或者至少可能是一个潜在客户)的唯一内容是apache和php错误日志的一些错误。
Apache尝试从本地主机运行脚本时显示此内容。
[Mon Dec 29 12:49:13.855653 2014] [authz_core:error] [pid 3632:tid 964] [client ::1:49206] AH01630: client denied by server configuration: C:/Apache24, referer: http://localhost/theturnbuckle/
并且php显示了这一点,虽然我已经重新安装了apche服务器,因为在安装之前和之后我将php_intl.dll和phpldap.dll移动到了wamp中的另一个文件夹,这些错误消失了。 (甚至不确定这是否是最好的做法)
[24-Dec-2014 12:00:37 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'c:/wamp/bin/php/php5.5.12/ext/php_intl.dll' - The specified module could not be found.
在第0行的未知中
[24-Dec-2014 12:00:37 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'c:/wamp/bin/php/php5.5.12/ext/php_ldap.dll' - The specified module could not be found.
在第0行的未知中
我取消注释了一些mysql服务器变量。
innodb_data_home_dir = C:\mysql\data/
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = C:\mysql\data/
innodb_log_arch_dir = C:\mysql\data/
最后我检查了一些php.ini服务器变量来尝试帮助解决问题,显示错误已经开启。
似乎安装了所有php扩展,例如php_pdo_mysql和php_mysqli。
但是在一天结束的时候,我正在黑暗中挣扎。
答案 0 :(得分:0)
你有两个警告:
[24-Dec-2014 12:00:37 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'c:/wamp/bin/php/php5.5.12/ext/php_intl.dll' - The specified module could not be found.
和
[24-Dec-2014 12:00:37 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'c:/wamp/bin/php/php5.5.12/ext/php_ldap.dll' - The specified module could not be found.
所以只需安装或启用这些扩展程序。