/fmake/libs/dataBase/utlMySqlWork.php

https://github.com/fmake/fmake · PHP · 114 lines · 88 code · 15 blank · 11 comment · 4 complexity · b6ba1c792258af366ce3eda2d932469f MD5 · raw file

  1. <?php
  2. namespace fmake\libs\dataBase;
  3. function errorExit()
  4. {
  5. echo "</td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table>\n";
  6. echo "<br><center><font color=red size=+2><?=_ERROR?></font><br><?=_SORRY?></center>\n";
  7. exit();
  8. }
  9. class utlMySqlWork
  10. {
  11. private $UserName;
  12. private $Password ;
  13. private $DatabaseName;
  14. private $HostName;
  15. private $Port ;
  16. private $DbCharSet ;
  17. private $ProjectName ;
  18. private $SelfName = null;
  19. private $Connection_id = null;
  20. private $CurrentResult = null;
  21. private $DoNotFreeResult = null;
  22. /**
  23. *
  24. * @var dataBaseController_logFile
  25. */
  26. private $log;
  27. function __construct($FileName,$db_user_name,$db_user_pas,$db_name,$db_host_name,$db_port,$db_crarset,$pr_name )
  28. {
  29. $this->UserName = $db_user_name;
  30. $this->Password = $db_user_pas;
  31. $this->DatabaseName = $db_name;
  32. $this->HostName = $db_host_name;
  33. $this->Port = $db_port;
  34. $this->DbCharSet = $db_crarset;
  35. $this->ProjectName = $pr_name;
  36. $this->SelfName=$FileName;
  37. }
  38. function addLog($log){
  39. $this -> log = $log;
  40. }
  41. function checkError($ss,$errLine) // �������� �� ������
  42. {
  43. if(mysql_errno($this->Connection_id)!=0)
  44. {
  45. $date=date("y-m-d H:i:s");
  46. echo "Project: $this->ProjectName \n\n<br>Date: $date <br>Script: $this->SelfName <br>Line: $errLine <br>Error(".mysql_errno()."):".mysql_error()."\n\n <br>in query: $ss <br><br><br>";
  47. ErrorExit();
  48. }
  49. }
  50. /**
  51. *
  52. * Соеединение к базе данных
  53. * @param $Line
  54. * @param $new_link bool если второе соединение к базе данных то необходимо указывать true
  55. */
  56. function connect($Line,$new_link = false)
  57. {
  58. $this->Connection_id = mysql_connect($this->HostName.":".$this->Port,$this->UserName,$this->Password,$new_link);
  59. $this->checkError("Connect to ".$this->HostName,$Line);
  60. //$this->query("SET CHARACTER SET ".$this->DbCharSet,$Line);
  61. $this->query("SET NAMES ".$this->DbCharSet,$Line);
  62. mysql_select_db($this->DatabaseName,$this->Connection_id);
  63. $this->checkError("Select ".$this->DatabaseName,$Line);
  64. }
  65. function query($ss,$Line)
  66. {
  67. if($this -> log){
  68. $this -> log -> add($ss);
  69. }
  70. if($this->CurrentResult>1){ if(!$this->DoNotFreeResult){ mysql_free_result($this->CurrentResult); }}
  71. $this->CurrentResult=mysql_query($ss,$this->Connection_id);
  72. $this->checkError($ss,$Line);
  73. return $this->CurrentResult;
  74. }
  75. function data_seek($i)
  76. {
  77. mysql_data_seek($this->CurrentResult, $i);
  78. }
  79. function fetch_array($type = MYSQL_BOTH)
  80. {
  81. return mysql_fetch_array($this->CurrentResult, $type);
  82. }
  83. function fetch_object()
  84. {
  85. return mysql_fetch_object($this->CurrentResult);
  86. }
  87. function num_rows()
  88. {
  89. return mysql_num_rows($this->CurrentResult);
  90. }
  91. function insert_id()
  92. {
  93. return mysql_insert_id($this->Connection_id);
  94. }
  95. function disconnect()
  96. {
  97. mysql_close($this->Connection_id);
  98. }
  99. }