Created
April 21, 2013 15:36
-
-
Save tamouse/5430012 to your computer and use it in GitHub Desktop.
Response to '[PHP] mysql_connect noob question' on php-general@lists.php.net
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 | |
error_reporting(-1); | |
ini_set('display_errors',1); | |
ini_set('display_startup_errors',1); | |
echo '<h1>$_POST:</h1>'.PHP_EOL; | |
echo '<pre><code>'.PHP_EOL; | |
echo htmlspecialchars(print_r($_POST,true)); | |
echo '</code></pre>'.PHP_EOL; | |
if (isset($_POST['submit'])) { | |
$dbuser = (isset($_POST['user']) && !empty($_POST['user'])) ? $_POST['user'] : null; | |
$dbpass = (isset($_POST['pass']) && !empty($_POST['pass'])) ? $_POST['pass'] : null; | |
$dbname = 'test001'; | |
$host = 'localhost'; | |
$db = new mysqli($host, $dbuser, $dbpass, $dbname); | |
if ($db->connect_error) { | |
echo '<pre><code>Connect Error: '. $db->connect_errno.': '.$db->connect_error.'</code></pre>'.PHP_EOL; | |
} else { | |
echo '<p>Connected!</p>'.PHP_EOL; | |
} | |
} | |
?> | |
<form method="post"> | |
Enter user/pw for data base: | |
<label for="user">User:</label><input name="user" type="text" value="" /> | |
<label for="pass">Pass:</label><input name="pass" type="text" value="" /> | |
<input type="submit" name="submit" value="Log in" /> | |
</form> |
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
grant select on test001.* to 'cheapuser'@'localhost' identified by 'secret'; |
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
http://db.tt/MiTbG7gx - successful login | |
http://db.tt/DKMnP4vs - unsuccessful login |
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
-- MySQL dump 10.13 Distrib 5.5.29, for debian-linux-gnu (i686) | |
-- | |
-- Host: localhost Database: test001 | |
-- ------------------------------------------------------ | |
-- Server version 5.5.29-0ubuntu0.12.04.2 | |
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; | |
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; | |
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; | |
/*!40101 SET NAMES utf8 */; | |
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; | |
/*!40103 SET TIME_ZONE='+00:00' */; | |
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; | |
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; | |
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; | |
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; | |
-- | |
-- Table structure for table `table1` | |
-- | |
DROP TABLE IF EXISTS `table1`; | |
/*!40101 SET @saved_cs_client = @@character_set_client */; | |
/*!40101 SET character_set_client = utf8 */; | |
CREATE TABLE `table1` ( | |
`id` int(11) NOT NULL AUTO_INCREMENT, | |
`name` varchar(50) DEFAULT NULL, | |
PRIMARY KEY (`id`) | |
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1; | |
/*!40101 SET character_set_client = @saved_cs_client */; | |
-- | |
-- Dumping data for table `table1` | |
-- | |
LOCK TABLES `table1` WRITE; | |
/*!40000 ALTER TABLE `table1` DISABLE KEYS */; | |
INSERT INTO `table1` VALUES (1,'bob'),(2,'ted'),(3,'carol'),(4,'alice'); | |
/*!40000 ALTER TABLE `table1` ENABLE KEYS */; | |
UNLOCK TABLES; | |
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; | |
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; | |
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; | |
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; | |
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; | |
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; | |
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; | |
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; | |
-- Dump completed on 2013-04-21 10:26:47 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment