반응형
PHP7에서 mysql_connect를 사용할 수 없어서 변경을 해줘야 합니다.
PHP7환경에서 mysql_connect() 를 사용하려면, mysqli_connect(), PDO::__construct()를 사용해야 합니다.
추가로 변경해야 하는 것들
mysql_connect
will be replaced bymysqli_connect
mysql_error
will be replaced bymysqli_error
and/ormysqli_connect_error
, depending on the contextmysql_query
will be replaced bymysqli_query
For instance:
- with mysql, you have to use the
mysql_select_db
once connected, to indicate on which database you want to do your queries - mysqli, on the other side, allows you to specify that database name as the fourth parameter to
mysqli_connect
. - Still, there is also a
mysqli_select_db
function that you can use, if you prefer.
참고: https://stackoverflow.com/questions/1390607/how-to-change-mysql-to-mysqli
참고2: https://stackoverflow.com/questions/34088373/call-to-undefined-function-mysql-connect-after-upgrade-to-php-7
참고3: http://php.net/manual/en/mysqli.select-db.php
참고4: http://php.net/manual/en/mysqli.query.php
[Others]
DB Class's
class Database {
/*This is a modular class that masks the underlying MySQL calls and provides a generic interface to its client. */
function __construct($host, $port, $dbname, $user, $password, $transactional = true) {
/* Ignore SSL since MySQL does not support it */
if ($port) {
$host = "$host:$port";
}
$this->Connection = new MySQLi($host, $user, $password, $dbname);
if ($transactional){
$this->Query("SET AUTOCOMMIT=0");
}
}
function Query($sql){
$this->Result = $this->Connection->query($sql);
if ($this->Result === false){
$this->HandleError($sql);
}
}
function Select($sql){
$this->Query($sql);
}
function Update($sql){
/* Right now this does the same thing as select...but it leaves room for expansion with replication */
$this->Query($sql);
}
function Next($associative = True){
/* Return the next row in the result set */
if($associative){
return $this->Result->fetch_assoc();
}
else {
return $this->Result->fetch_array();
}
}
function ResultLength(){
return $this->Result->num_rows;
}
function HandleError($sql) {
/* This function should be overridden to provide custom error handling for the application */
// die(ErrorMessage("mysql", "MySQL Error in $sql: " . mysql_error($this->Connection))); NOT SURE WHAT TO DO WITH THIS
}
function Commit(){
$this->Query("COMMIT");
}
function Rollback(){
$this->Query("ROLLBACK");
}
}
include("shared.inc.php");
class StoredProcedure {
/*This is a modular class that provides a generic interface for calling stored procedures or the equivalent */
function StoredProcedure($name, $update, $parameters, $defaults){
$this->name = $name;
$this->update = $update;
$this->parameters = $parameters;
$this->defaults = $defaults;
}
function GetQuery($arguments){
global $StoredProcedures;
$callparameters = array();
foreach($this->parameters as $parameter){
if(isset($arguments[$parameter])){
$callparameters[] = $this->Escape($arguments[$parameter]);
}
else if (isset($this->defaults[$parameter])){
$callparameters[] = $this->Escape(DefaultParameter($this->defaults[$parameter]));
}
else {
die(MissingParameterError($parameter));
}
}
return vsprintf($StoredProcedures[$this->name], $callparameters);
}
function ReturnsRows() { //Does this stored procedure return a recordset?
return ($this->update == false);
}
function Escape($value){
if ($value === false){
return "NULL";
}
return "'" . mysql_escape_string($value) . "'";
}
function Call(&$database, $arguments){
if ($this->update){
$database->Update($this->GetQuery($arguments));
}
else {
$database->Select($this->GetQuery($arguments));
}
}
}
참고: https://www.experts-exchange.com/questions/28935887/mysql-connect-PHP-7.html
반응형
'WEB언어 > PHP' 카테고리의 다른 글
PhpStome UI 다크모드 사용하기 (JetBrain제품들 다 지원- Darcula) (0) | 2019.10.10 |
---|---|
IIS + PHP에서 알수 없는 500번 오류 (0) | 2019.10.05 |
[PHP] break / return / exit 차이점 (2) | 2019.07.31 |
[PHP] 하나 은행 환율 API를 통한 JSON (14) | 2018.12.06 |
PHP 현재 자신의 파일명 가져오기 basename($_SERVER['PHP_SELF']); (0) | 2018.05.15 |
php 이미지 자르기(crop) 만들기 (0) | 2018.05.09 |
[펌] PHP 7.0에서 새로 나온 NULL 병합 연산자 - ?? (0) | 2018.04.14 |
[PHP] goto_url 로 페이지 이동하기 (0) | 2018.03.27 |
도움이 되셨다면 하트모양의 "♡ 공감"을 눌러주시면 큰 격려가 됩니다.
(로그인하지 않으셔도 가능)
(로그인하지 않으셔도 가능)