How to run a SQL script or file?
I am really confused after so many hours I cannot create a mysql Table
with the options that I have in my sql file!
I will past the php file I created, but it doesnt work:
<?PHP
$con=mysqli_connect("www.host.com","dbname","password","password");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Create table
$sql=" DROP TABLE IF EXISTS `visitor_tracking`;
CREATE TABLE IF NOT EXISTS `visitor_tracking` (
`entry_id` int(11) NOT NULL auto_increment,
`visitor_id` int(11) default NULL,
`ip_address` varchar(15) NOT NULL,
`page_name` text,
`query_string` text,
`timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
PRIMARY KEY (`entry_id`),
KEY `visitor_id` (`visitor_id`,`timestamp`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=22 ;"
// Execute query
if (mysqli_query($con,$sql))
{
echo "Table persons created successfully";
}
else
{
echo "Error creating table: " . mysqli_error($con);
}
?>
The sql is from a Visitor Tracking system used on websites! I want to
create an installer.php file, instead of going to phpmyadmin add the sql
file!
And this is the SQL File copied from the Database.sql file:
DROP TABLE IF EXISTS `visitor_tracking`;
CREATE TABLE IF NOT EXISTS `visitor_tracking` (
`entry_id` int(11) NOT NULL auto_increment,
`visitor_id` int(11) default NULL,
`ip_address` varchar(15) NOT NULL,
`page_name` text,
`query_string` text,
`timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
PRIMARY KEY (`entry_id`),
KEY `visitor_id` (`visitor_id`,`timestamp`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=22 ;
I really hope some one could help me fix the issue!
Thank you very much in advance
No comments:
Post a Comment