简体   繁体   English

在PHP中使用WebMatrix创建安全的MySQL数据库连接

[英]Creating a secure mySQL database connection with WebMatrix in php

I've created a connection script to my database in WebMatrix with php by learning from a book, and it states I should place the connection script outside the web directory so people can't access it in the browser. 我通过学习一本书,用php在WebMatrix中创建了到我的数据库的连接脚本,它指出我应该将连接脚本放置在Web目录之外,以使人们无法在浏览器中访问它。 But if I do that I don't know how I'm supposed to retrieve it since every import/include starts at the web directory. 但是如果这样做,我不知道应该如何检索它,因为每个import / include都从Web目录开始。

Can someone tell me how to achieve this please? 有人可以告诉我如何实现吗? Thank you. 谢谢。

My connection script: 我的连接脚本:

 <?php
 # Selects the database

 DEFINE ('DB_USER', 'secret');
 DEFINE ('DB_PASSWORD', 'secret');
 DEFINE ('DB_HOST', 'localhost');
 DEFINE ('DB_NAME', 'secret');

 $dbc_accounts = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not       connect to MySQL');

 @mysql_select_db (DB_NAME) OR die ('Could not select the database');

 // Function for escaping data
 function escape_data ($data) 
 {
     global $dbc_accounts;
     if (ini_get('magic_quotes_gpc')) 
     {
         $data = stripslashes($data);
     }
     return mysql_real_escape_string(trim($data), $dbc_accounts);
 }

using it: 使用它:

 require_once ('mysql_connect.php');
require_once ('../some/place/secure/mysql_connect.php');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM