Created
June 6, 2014 20:16
-
-
Save zazk/753d44c1d156e6123c0d to your computer and use it in GitHub Desktop.
Execute an SQL Query with PDO - PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Execute an SQL Query with PDO | |
$table = "company"; | |
try { | |
$db = new PDO("mysql:dbname=socialpi_openmobile;host=localhost", "socialpi_opmo", "openmo" ); | |
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );//Error Handling | |
$sql =" | |
DROP TABLE IF EXISTS `contacto`; | |
CREATE TABLE IF NOT EXISTS `contacto` ( | |
`contactoid` int(5) NOT NULL AUTO_INCREMENT, | |
`name` varchar(255) NOT NULL DEFAULT '', | |
`company` varchar(255) DEFAULT '', | |
`email` varchar(255) NOT NULL DEFAULT '', | |
`message` text, | |
`date_created` date DEFAULT '0000-00-00', | |
`first` varchar(55) NOT NULL, | |
`second` varchar(55) NOT NULL, | |
`third` varchar(55) NOT NULL, | |
`fourth` varchar(55) NOT NULL, | |
PRIMARY KEY (`contactoid`) | |
) ENGINE=MyISAM ; | |
" ; | |
$db->exec($sql); | |
print("Created $table Table.\n"); | |
} catch(PDOException $e) { | |
echo $e->getMessage();//Remove in production code | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment