我有一个PHP脚本,用于连接MySQL数据库.通过mysql_connect连接工作完美,但在尝试使用PDO时,我收到以下错误:
SQLSTATE[HY000] [2005] Unknown MySQL server host 'hostname' (3)
Run Code Online (Sandbox Code Playgroud)
我用来连接的代码如下:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
$hostname_localhost ="hostname";
$database_localhost ="dbname";
$username_localhost ="user";
$password_localhost ="pass";
$user = $_GET['user'];
$pass = $_GET['pass'];
try{
$dbh = new PDO("mysql:host=$hostname_localhost;dbname=$database_localhost",$username_localhost,$password_localhost);
echo 'Connected to DB';
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $dbh->prepare("SELECT check_user_company(:user,:pass)");
$stmt = $dbh->bindParam(':user',$user,PDO::PARAM_STR, 16);
$stmt = $dbh->bindParam(':pass',$pass,PDO::PARAM_STR, 32);
$stmt->execute();
$result = $stmt->fetchAll();
foreach($result as $row)
{
echo $row['company_id'].'<br />';
}
$dbh = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
Run Code Online (Sandbox Code Playgroud)
提前致谢
我在Android开发人员的摄像头上遇到了问题,这是我的代码:
// create Intent to take a picture and return control to the calling application
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
// create a file to save the image
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
// start the image capture Intent
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
Run Code Online (Sandbox Code Playgroud)
问题是'MEDIA_TYPE_IMAGE',它表示无法将其解析为变量.我将mediastore,camera和URI导入到我的项目中.提前致谢!