smartyに接続ができません 環境はmacosでxamppを使用しています
また、もともとクラスで囲っていいたものを分解しようとしています。
smartyの位置は
/Applications/XAMPP/Smarty/libs/Smarty.class.php です
php
1<?php 2 2 require_once('d:/xampp/smarty/libs/Smarty.class.php'); 3 3 //require_once('Database.class.php'); 4 4 require_once('config.php'); 5 5 6 6 $smarty = new Smarty(); 7 7 $db = new Database(DB_HOST, DB_USER, DB_PASS, DB_NAME); 8 8 //テンプレートディレクトリ指定 9 9 $smarty->template_dir = '..¥templates¥board'; 10 10 $smarty->compile_dir = '..¥templates_c¥board'; 11 11 12 12 $msg = ''; 13 13 $err_msg = ''; 14 14 if(isset($_POST['send']) === true){ 15 15 $name = $_POST['name']; 16 16 $contents = $_POST['contents']; 17 17 18 18 if($name !== '' && $contents !== ''){ 19 19 $query = "INSERT INTO board (" 20 20 ."name," 21 21 ."contents" 22 22 .")VALUES(" 23 23 .$db->str_quote($name)."," 24 24 .$db->str_quote($contents) 25 25 .")"; 26 26 $res = $db->execute($query); 27 27 if($res !== false){ 28 28 $msg = '書き込みに成功しました'; 29 29 }else{ 30 30 $err_msg = '書き込みに失敗しました'; 31 31 } 32 32 }else{ 33 33 $err_msg = '名前とコメントを記入してください'; 34 34 } 35 35 } 36$query = "SELECT" 37 38 ."id," 38 39 ."name," 39 40 ."contents" 40 41 ."FROM" 41 42 ."board"; 42 43 43 44 $data = $db->select($query); 44 45 $db->close(); 45 46 $smarty->assign('msg',$msg); 46 47 $smarty->assign('err_msg',$err_msg); 47 48 $smarty->assign('data',$data); 48 49 49 50 $smarty->dispaly('board5.tpl'); 50 51 ?> 51 52 <?php 52 53 $this->db_con = $this->connectDB($db_host,$db_user,$db_pass,$db_name); 53 54 $this->db_host = $db_host; 54 55 $this->db_user = $db_user; 55 56 $this->db_pass = $db_pass; 56 57 $this->db_name = $db_name; 57function connectDB($db_host,$db_user,$db_pass,$db_name) 58 61 { 59 62 60 63 $tmp->db_con = mysqli_connect($db_host, $db_user, $db_pass, $db_name); 61 64 62 65 if($tmp_con !== false){ 63 66 return $tmp_con; 64 67 }else{ 65 68 printf("Connect failed: %s¥n", mysqli_connect_error()); 66 69 exit; 67 70 } 68 71 } 69 72 70 73 function execute ($sql) 71 74 { 72 75 return mysqli_query($sql); 73 76 } 74 77 function select($sql) 75 78 { 76 79 $res = execute($sql); 77 80 $data = array(); 78 81 while ($row = mysqli_fetch_array($res)){ 79 82 array_push($data,$row); 80 83 } 81 84 //mysql_free_result($res); 82 85 return $data; 83 86 } 84 87 function quote($int) 85 88 { 86 89 return mysqli_real_escape_string($db_con , $int); 87 90 } 88 91 function str_quote($str) 89 92 { 90 93 return "'".mysqli_real_escape_string($db_con,$str)."'"; 91 94 } 92function getLastld() 93 97 { 94 98 return mysqli_insert_insert_id($db_con); 95 99 } 96100 97101 function close() 98102 { 99103 mysqli_close($db_con); 100104 }
エラーメッセージ
Warning: require_once(d:/xampp/smarty/libs/Smarty.class.php): failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/board/board5.php on line 2
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。