pdo

POSTGRESQL INSERT if specific row name don't exists !

99封情书 提交于 2020-01-06 15:18:19
问题 I'm trying to INSERT in my Postgresql database only if my model don't exists. I'm using PDO connection, I try IGNORE and ON DUPLICATE KEY UPDATE but with errors in PDO / syntax. MY Code: if(isset($_POST['insertModel'])){ require("includes/connection.php"); $models = $_POST['name']; $parametros = array($models); $sth = $dbh->prepare("INSERT INTO models (name) VALUES ( ? )"); $sth->execute($parametros); if($sth){ header("location: admin.php?model_inserted=1"); } } Thanks 回答1: ON DUPLICATE KEY

Listing issue, GROUP mysql

好久不见. 提交于 2020-01-06 14:44:15
问题 Here is a mock-up example of Mysql table: | ID | Country | City | ________________________________ | 1 | Sweden | Stockholm | | 2 | Sweden | Stockholm | | 3 | Sweden | Lund | | 4 | Sweden | Lund | | 5 | Germany | Berlin | | 6 | Germany | Berlin | | 7 | Germany | Hamburg | | 8 | Germany | Hamburg | Notice how both rows Country and city have repeated values inside them. Using GROUP BY country, city in my PDO query, the values will not repeat while in loop . Here is PDO for this: $query =

PHP PDO mssql error

好久不见. 提交于 2020-01-06 14:21:08
问题 I was using mssql pdo for PHP 5.3.1, It was running without any problems, suddenly I have found, all my insert queries fails while running from php PDO, If I echo the query and run it in SQL server Management studio, It runs without any error. below is my echo query INSERT INTO contactus(title, first_name, last_name, email) VALUES('Mr', 'Robin', 'Michael', 'robin@robin.com') below is the error Array ( [0] => HY000 [1] => 10007 [2] => Incorrect syntax near 'Mr'. [10007] (severity 5) [INSERT

No error: PDO constructor was not called in

こ雲淡風輕ζ 提交于 2020-01-06 14:02:46
问题 Good afternoon. I'm starting using the PDO yesterday, and I have some problem with this. I was creating extendet class, which doesn't work and I can't find the bug. This is code of my helper class, for work witch PDO: class EPDO extends PDO { /** Some identificator of connection*/ public $db; /** * Creating new PDO connections */ public function __construct($dbhost, $dbname, $dbuser = 'root', $dbpass = '', $dbtype = 'mysql') { $db = new PDO($dbtype . ':host=' . $dbhost . ';dbname=' . $dbname,

php pdo statement error

北慕城南 提交于 2020-01-06 13:10:03
问题 I'm a newbie to php pdo. Here i'm trying to fetch my database records from database using prepared statements. But it didn't fetch the records. I'm getting this following error Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected why i'm getting this error? why it didn't fetch the records from database? <?php $user = "root"; $password = "password"; try { $conn = new PDO('mysql:host=localhost;database=evouchers', $user,

pdo bindParam case sensitive

折月煮酒 提交于 2020-01-06 12:18:28
问题 I want to check if the password is correct (Case sensitive). Currently, I'm using PDO, something like this: $sql = 'select * from User WHERE Email = :user and Password = :pass AND idRole = :role AND idState_User = :state'; $stat = $this->_db->prepare($sql); $stat->bindParam(':user', $user, PDO::PARAM_STR); $stat->bindParam(':pass', $password, PDO::PARAM_STR); $stat->bindParam(':state', $idState_User, PDO::PARAM_INT); $stat->bindParam(':role', $idRole, PDO::PARAM_INT); $stat->execute(); I

pdo bindParam case sensitive

只愿长相守 提交于 2020-01-06 12:15:10
问题 I want to check if the password is correct (Case sensitive). Currently, I'm using PDO, something like this: $sql = 'select * from User WHERE Email = :user and Password = :pass AND idRole = :role AND idState_User = :state'; $stat = $this->_db->prepare($sql); $stat->bindParam(':user', $user, PDO::PARAM_STR); $stat->bindParam(':pass', $password, PDO::PARAM_STR); $stat->bindParam(':state', $idState_User, PDO::PARAM_INT); $stat->bindParam(':role', $idRole, PDO::PARAM_INT); $stat->execute(); I

Connect multiple tables using LEFT OUTER JOIN

北慕城南 提交于 2020-01-06 09:01:49
问题 I'm trying to get data from multiple tales using LEFT OUTER JOIN but I'm getting a fatal error. Table names, field names, db connection are correct. $sql = "SELECT shipping_info.shipping_id, service1.service, package1.package_type, countries1.country AS fromCountry, countries2.country AS toCountry, countries3.country AS resiCountry, customer1.name, FROM shipping_info LEFT OUTER JOIN service_types AS service1 ON shipping_info.service_type = service_types.serviceType_id LEFT OUTER JOIN package

UPDATE query with prepared statements

北城余情 提交于 2020-01-06 09:01:10
问题 Having problems with and update query i keep getting Warning: Crud::update() [crud.update]: Property access is not allowed yet in crud.php on line 60 This is my code $stmt = $this->mysql->prepare('UPDATE links SET title = ?, url = ?, comment = ? WHERE id = ?'); $stmt->bind_param('sssi',$title,$url,$comment,$id); $stmt->execute(); $stmt->close(); on line 60 return $stmt->affected_rows; Googled it and only found one reference in the php documentation in a comment but i couldn't understand the

PDO Prepare statement not processing parameters

[亡魂溺海] 提交于 2020-01-06 08:33:26
问题 I've exhausted all efforts at what appears to be a trivial problem, but gotten nowhere. There is a simple Prepare statement: $qry = $core->db->prepare("SELECT * FROM users WHERE email = '?'"); $qry->execute(array('email@address.com')); However, no rows are returned. Running the query with the parameters hardcoded into the query results in a successful selection of one row. I've tryed many different methods of doing the prepare, but even it this most simple form it isn't working. The PDO